package com.bridgeQQ.client.control.commands
{
	import com.bridgeQQ.client.core.ICommand;
	import com.bridgeQQ.client.model.BridgeModel;
	import com.bridgeQQ.client.util.ModelUtil;
	import com.bridgeQQ.client.vo.FriendType;
	import com.bridgeQQ.client.vo.User;

	public class ChangeFriendTypeCommand extends BaseWrapper implements ICommand
	{
		public function ChangeFriendTypeCommand(respond:BaseRespond)
		{
			super(respond);
		}
		
		protected override function result(info:Object):void
		{
			var result:Object = info.respond.value;
			if(result == null || !result.result)
			{
				fault(info);
				return;
			}
			var oldID:Number = info.oldTypeID;
			var newID:Number = info.newTypeID;
			var friend:String = info.friend;
			
			var oldFT:FriendType = ModelUtil.getFriendType(BridgeModel.instance.possess, oldID);
			
			var oldIndex:int = ModelUtil.findFriendAtType(friend, oldFT);
			var user:Object;
			if(oldIndex >= 0)
			{
				user = oldFT.friends.removeItemAt(oldIndex);
			}
			var newFT:FriendType = ModelUtil.getFriendType(BridgeModel.instance.possess, newID);
			oldIndex = ModelUtil.findFriendAtType(friend, newFT);
			if(oldIndex < 0 && user is User)
			{
				newFT.friends.addItem(user);
			}
			BridgeModel.instance.possess.friendTypes.refresh();
		}
		
		protected override function fault(info:Object):void
		{
			
		}
	}
}